import configparser
import os

class ConfigParser:
    """配置文件解析器"""
    _instance = None
    _config = None
    
    def __new__(cls, config_file=None):
        if not cls._instance:
            cls._instance = super().__new__(cls)
            cls._instance._init_config(config_file)
        return cls._instance
    
    def _init_config(self, config_file):
        # 获取配置文件路径
        if not config_file:
            base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
            config_file = os.path.join(base_dir, 'config', '../config/config.ini')
        
        # 读取配置文件
        self._config = configparser.ConfigParser()
        self._config.read(config_file, encoding='utf-8')
    
    @classmethod
    def get_config(cls, config_file=None):
        """获取配置实例"""
        return cls(config_file)._config    